#include "InputLayout.h"
#include "VertexShader.h"

InputLayout::InputLayout(Graphics & gfx, const VertexShader & vs, Usage usage) : usage(std::move(usage))
{
	auto classify = static_cast<D3D11_INPUT_CLASSIFICATION>(usage);
	D3D11_INPUT_ELEMENT_DESC layoutD[] =
	{
		{"POSITION",0,DXGI_FORMAT_R32G32B32_FLOAT,0,0,classify,0},
		{"NORMAL",0,DXGI_FORMAT_R32G32B32_FLOAT,0,12,classify,0}, 
		{"TANGENT",0,DXGI_FORMAT_R32G32B32_FLOAT,0,24,classify,0},
		{"TEXCOORD",0,DXGI_FORMAT_R32G32_FLOAT,0,36,classify,0},
	};
	const auto blob = vs.GetBytecode();
	HR(GetDevice(gfx)->CreateInputLayout(layoutD, (UINT)std::size(layoutD), blob->GetBufferPointer(), blob->GetBufferSize(), &inputlayout));
}

void InputLayout::Bind(Graphics & gfx)
{
	GetContext(gfx)->IASetInputLayout(inputlayout.Get());
}

std::shared_ptr<InputLayout> InputLayout::Create(Graphics & gfx, const VertexShader & vs, Usage usage)
{
	return std::make_shared<InputLayout>(gfx,vs,usage);
}
